/*
 * @Description: T节点录入
 * @Author: cgt
 * @Date: 2021-11-26 14:11:06
 * @LastEditors: cgt
 * @LastEditTime: 2021-12-28 19:44:58
 */
import { getSblxBySbzlx } from '../../../../../mapUtils/SblxUtil';
import { projectLngLatToWebMercator } from '../../../../../mapUtils/CoordinateUtil';
import CONST from '../../../../../constant/Common';
import IpmsPoint from '../IpmsPoint';
import RuleResult from '../vo/RuleResult';

/**
 * 变电站修改
 * @implements {IpmsPoint}
 */
class PmsPjd extends IpmsPoint {
  constructor(_tool) {
    super(_tool);
    this.defaultSbzlx = '10200002';
    this.drawtype = 'pms_pjd';
    this.defaultName = '新增Π接点';
    this.defaultIcon = 'bdz_default_32';
  }

  /**
   * 新增变电站
   * @override
   * @param {Object} option 默认参数
   * @param {Array} snapList 捕捉图形
   */
  draw(option, snapList) {
    return super.draw(option, snapList);
  }

  /**
   * 编辑变电站
   * @override
   * @param {Object} option 默认参数
   * @param {Array} snapList 捕捉图形
   */
  edit(option, snapList) {
    return super.edit(option, snapList);
  }

  /**
   * 获取当前绘制设备信息
   * @override
   */
  async getTargetDevice() {
    let coordinates = projectLngLatToWebMercator(this.geometry.coordinates);
    var startDevice = this.getStartDevice();
    var sliceInfo = this.getSliceInfo();
    var { start, finish, between, rotate } = sliceInfo;

    // 获取分隔线
    let data = {
      sbmc: this.option.sbmc || this.defaultName,
      dydj: startDevice.dydj, // 取捕捉线路的电压等级
      schema: this.option.schema,
      versionid: this.option.versionid || '',
      ghrw: this.option.ghrw || '',
      ghfa: this.option.ghfa || '',
      ghnf: this.option.ghnf || '',
      ghxm: this.option.ghxm || '',
      ssqy: this.option.ssqy || '',
      city: this.option.city || '',
      fxlx: this.option.fxlx || 2,
      away: 0,
      verRule: CONST.verRule,
      sblx: getSblxBySbzlx(this.defaultSbzlx),
      sbzlx: this.defaultSbzlx,
      shape: this.getGeometryWkt(this.geometry),
      coordinates: coordinates,
      startDevice: startDevice,
      sliceInfo: {
        start: this.getGeometryWkt(start.geometry),
        finish: this.getGeometryWkt(finish.geometry),
        between: this.getGeometryWkt(between.geometry),
        rotate: rotate,
        intersects: sliceInfo.intersects
      }
    };
    return data;
  }

  /**
   * 验证点合理性
   * @override
   * @param {Number} index 点下标
   * @param {*} snap 捕捉到的设备
   */
  async _ruleJudgePoint(index, snap) {
    if (snap && snap.layer) {
      var device = this.getStartDevice();
      if(this._isLine(device.sbzlx)) {
        var sliceInfo = this.getSliceInfo();
        var { start, finish, between } = sliceInfo;
        if(start && finish && between) {

          return new RuleResult(true, index);
        }
        return new RuleResult(false, index, '生成Π接点失败');

      }
    }

    return new RuleResult(false, index, 'Π接点必须在线路上');
  }

}

export default PmsPjd;
